﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AccSystem;

namespace Local_Government_Unit
{
    public partial class Login : Form
    {
        ACcountSystem AccountSystem = new ACcountSystem();
        public Login()
        {
            
            InitializeComponent();
            btnlogin.Click += new EventHandler(btnlogin_Click);
        }

        void btnlogin_Click(object sender, EventArgs e)
        {
            info();

        }
        public void info()
        {
            if (txtusername.Text == "")
            {
                MessageBox.Show("Please input username", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                txtusername.Focus();
                return;
            }
            else if (txtpassword.Text == "")
            {
                MessageBox.Show("Please input Password", "Informatoion", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                txtpassword.Focus();
                return;
            }
            
            AccountSystem.Query("SELECT * FROM tblusers WHERE Username = '" + txtusername.Text + "'AND Password = '" + txtpassword + "'");
            if (AccountSystem.dt.Rows.Count > 0)
            {
                string position = AccountSystem.dt.Rows[0]["Position"].ToString();
                Form1 frm1 = new Form1();
                //frm1.LevelofAccess(position);

                frm1.ShowDialog();
                this.Close();
            }
            else
            {
                txtusername.Clear();
                txtpassword.Clear();
                MessageBox.Show("Incorrect Password or Username", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                txtusername.Focus();
                return;

            }
            txtusername.Clear();
            txtpassword.Clear();
        }
    }
}
